package com.hyst.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hyst.common.ResultBean;
import com.hyst.common.ResultPage;
import com.hyst.domain.ReportView;
import com.hyst.service.ReportViewService;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description:controller
 * @author：dy 
 *@Date：2018年09月08日
 */
@RestController
@RequestMapping("reportViews")
@CrossOrigin(maxAge = 3600, origins = "*")
public class ReportViewController {
	@Autowired
	private ReportViewService reportViewService;
	
	@GetMapping
	public ResultPage<ReportView> getProjects(ReportView reportView) {
		System.err.println(reportView);
		return ResultPage.success(reportViewService.list(reportView));
	}

	@PostMapping
	public ResultBean<ReportView> creat(final ReportView reportView) {
		return ResultBean.success(reportViewService.insert(reportView));
	}

	/**
	 * @Description: 根据主键查询
	 * @param id
	 * @return ResultBean<ReportView>
	 */
	@GetMapping("{id}")
	public ResultBean<ReportView> getByPriKey(@PathVariable("id") final Integer id) {
		return ResultBean.success(reportViewService.getByPriKey(id));
	}


	@GetMapping("/type2/{id}")
	public ResultBean<ReportView> getByTypePriKey(@PathVariable("id") final Integer id, @RequestParam("type") Integer type) {
		return ResultBean.success(reportViewService.getByPriKey(id));
	}


	/**
	 * @Description: 根据主键更新全字段
	 * @param reportView
	 * @return ResultBean<ReportView>
	 */
	@PatchMapping("{id}")
	public ResultBean<ReportView> update(final ReportView reportView) {
		return ResultBean.success(reportViewService.update(reportView));
	}

	/**
	 * @Description: 根据主键更新不为默认值的字段
	 * @param reportView
	 * @return ResultBean<ReportView>
	 */
	//@PutMapping("{id}")
	@PostMapping("id")
	public ResultBean<ReportView> updatePatch(@PathVariable("id") final Integer id,
			final ReportView reportView) {
		return ResultBean.success(reportViewService.updateSelective(reportView));
	}

	/**
	 * @Description: 根据主键删除
	 * @param id
	 * @return ResultBean<ReportView>
	 */
	@DeleteMapping("{id}")
	public ResultBean<ReportView> delete(@PathVariable("id") final Integer id) {
		return ResultBean.success(reportViewService.delete(id));
	}

	@GetMapping("/type/{id}")
	public ResultBean<ReportView> getByTypePriKey(@PathVariable("id") final Integer id, @RequestParam("type") String type, HttpServletRequest request) {
		return (reportViewService.getByTypePriKey(id, type,request));
	}

}
